package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.user.constants.UserRetCode;
import com.cskaoyan.user.dto.UserLogoutResponse;
import com.cskaoyan.user.service.UserLogoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author sosog
 * @version 1.0.0
 * @description TODO
 * @date 2022/6/20 11:31
 */
@RestController
public class UserLogoutController {

    @Autowired
    UserLogoutService logoutService;

    @GetMapping("/user/loginOut")
    public ResponseData logout(HttpServletRequest request, HttpServletResponse servletResponse) {
        UserLogoutResponse response = logoutService.logout(request, servletResponse);
        if (response.getCode().equals(UserRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(response);
        }
        return new ResponseUtil<>().setErrorMsg(response.getMsg());
    }
}
